{-# OPTIONS -Wall #-}

--------------------------------------------------------------------------------
-- |
-- Module      :  WumpusExpr.Types
-- Copyright   :  (c) Stephen Tetley 2012
-- License     :  BSD3
--
-- Maintainer  :  stephen.tetley@gmail.com
-- Stability   :  unstable
-- Portability :  GHC
--
-- Types.
--
--------------------------------------------------------------------------------

module WumpusExpr.Types
  (
    Decimal

  , Type(..)
  , ppType

  ) where


import Text.PrettyPrint.HughesPJ                -- package: pretty

import Data.Fixed

type Decimal = Fixed E9  


-- | We pretend PostScript has a Symbol type to accommodate font
-- names (e.g. /Courier) which are clearly different to Strings.
--
-- We have Radian as a type - this gives us a strong reminder to 
-- print angle values as radians (Canvas) or degrees (PostScript).
-- 
data Type = TyUnit
          | TyBool
          | TyInt
          | TyFloat
          | TyRadian
          | TyString
          | TyPsSymbol
          | TyFun [Type] Type
          | TyMon Type
  deriving (Eq,Ord,Show)




ppType :: Type -> Doc
ppType TyUnit           = text "()"
ppType TyBool           = text "Bool"
ppType TyInt            = text "Int"
ppType TyFloat          = text "Float"
ppType TyRadian         = text "Radian"
ppType TyString         = text "String"
ppType TyPsSymbol       = text "PS_Symbol"
ppType (TyFun ts t)     = pre <+> ppType t
  where
    pre = hsep $ map (\x -> ppType x <+> text "->") ts

ppType (TyMon t)        = text "Mon" <+> case t of
   TyMon {} -> parens (ppType t)
   TyFun {} -> parens (ppType t)
   _        -> ppType t